home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
PowerPlant
/
AGA Classes 1.2
/
Sliders
/
LAGASliderBase.cp
< prev
next >
Wrap
Text File
|
1996-06-30
|
9KB
|
332 lines
// ===========================================================================
// LAGASliderBase.cp
// ===========================================================================
// “Apple Grayscale Appearance” compliant slider abstract base class
// Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
//
// You may use this source code in any application (commercial, shareware, freeware,
// postcardware, etc), but not remove this notice (no need to acknowledge the use of
// this class in the about box)
// You may not sell this source code in any form. This source code may be placed on
// publicly accessable archive sites and source code disks. It may not be placed on
// profit archive sites and source code disks without the permission of the author,
// Christophe ANDRES.
//
// This source code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// If you make any change or improvement on this class, please send the improved/changed
// version to : chrisoft@calva.net or Christophe ANDRES
// 20, rue Prosper Mérimée
// 67100 STRASBOURG
// FRANCE
//
// ===========================================================================
// LAGASliderBase.h <- double-click + Command-D to see class declaration
//
// LAGASliderBase is an abstract class used by all the AGA slider classes to perform common duties
//
// This class requires AGAColors.cp to be present in your project
//
// Version : 1.2
//
// Change History (most recent first, date in US form : mm/dd/yy):
//
// 06/30/96 ca Public release of version 1.2
// 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
// in order that triState_Latent state is drawn as disabled
// 06/04/96 ca Increased version to 1.2
// 05/16/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
// (version 1.1)
//
// To Do:
//
#include "LAGASliderBase.h"
#include "AGAColors.h"
#include <UDrawingState.h>
#include <PP_Types.h>
#define kTriggerDistance 2
//-------Constructors/Destructors-------------------------------------------------------------------------------------
LAGASliderBase::LAGASliderBase ()
{
mGhostPointer = nil;
mGhostMask = nil;
::SetRect(&mLastGhost, 0, 0, 0, 0);
mLastPosition.h = mLastPosition.v = 0;
mTrackOriginTinkering = 0;
mRightBottomPointing = mVerticalSlider = true;
if (mMaxValue == mMinValue)
mMaxValue++; // So we have at least two values to slide from
}
LAGASliderBase::LAGASliderBase (LStream *inStream) : LControl(inStream)
{
mGhostPointer = nil;
mGhostMask = nil;
::SetRect(&mLastGhost, 0, 0, 0, 0);
mLastPosition.h = mLastPosition.v = 0;
mTrackOriginTinkering = 0;
unsigned char theBoolean;
inStream->ReadData(&theBoolean, sizeof(unsigned char));
mVerticalSlider = (theBoolean != 0);
inStream->ReadData(&theBoolean, sizeof(unsigned char));
mRightBottomPointing = (theBoolean != 0);
if (mMaxValue == mMinValue)
mMaxValue++; // So we have at least two values to slide from
}
LAGASliderBase::LAGASliderBase (const LAGASliderBase &inOriginal) : LControl(inOriginal)
{
mGhostPointer = nil;
mGhostMask = nil;
::SetRect(&mLastGhost, 0, 0, 0, 0);
mLastPosition.h = mLastPosition.v = 0;
mTrackOriginTinkering = 0;
mVerticalSlider = inOriginal.mVerticalSlider;
mRightBottomPointing = inOriginal.mVerticalSlider;
}
LAGASliderBase::LAGASliderBase (const SPaneInfo &inPaneInfo, MessageT inValueMessage, Boolean inVertical,
Boolean inBottomRightPointer, Int32 inInitialValue, Int32 inMinValue, Int32 inMaxValue)
: LControl(inPaneInfo, inValueMessage, inInitialValue, inMinValue, inMaxValue)
{
mGhostPointer = nil;
mGhostMask = nil;
::SetRect(&mLastGhost, 0, 0, 0, 0);
mLastPosition.h = mLastPosition.v = 0;
mTrackOriginTinkering = 0;
mVerticalSlider = inVertical;
mRightBottomPointing = inBottomRightPointer;
}
LAGASliderBase::~LAGASliderBase ()
{
if (mGhostPointer != nil)
FinishGhost();
}
//-------Drawers----------------------------------------------------------------------------------------------------
void LAGASliderBase::DrawSelf ()
{
StClipRgnState clip;
Rect frame;
CalcLocalFrameRect(frame);
clip.ClipToIntersection(frame); // You never know if the guy that placed it in Constructor has made it big enough ;)
DrawSlideTrack();
DrawLabels();
DrawIndicator(false);
}
void LAGASliderBase::DrawSlideTrack ()
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
Rect frame;
short origin;
theState.Normalize();
CalcLocalFrameRect(frame);
if (mVerticalSlider)
{
origin = (mRightBottomPointing ? frame.left : frame.right - 13);
origin += mTrackOriginTinkering;
if (hasColor)
{
::RGBBackColor(&gAGAColorArray[(disabled ? 4 : 5)]);
Rect tempR = frame;
tempR.top++;
tempR.bottom--;
tempR.left = origin + 3;
tempR.right = tempR.left + 5;
::EraseRect(&tempR);
}
if (disabled)
{
if (hasColor)
::RGBForeColor(&gAGAColorArray[8]);
else
::PenPat(&qd.gray);
}
::MoveTo(origin + 5, frame.top + 1);
::Line(2, 0); ::Move(1, 1);
::Line(0, (frame.bottom - frame.top) - 4);
::Move(-1, 1); ::Line(-2, 0);
::Move(-1, -1); ::Line(0, -((frame.bottom - frame.top) - 4));
if (hasColor)
{
::RGBForeColor(&gAGAColorArray[(disabled ? 4 : 5)]);
::Move(0, -2); ::Line(3, 0);
::ForeColor(whiteColor);
::Move(1, 1); ::Line(0, 0);
::Move(1, 1); ::Line(0, (frame.bottom - frame.top) - 3);
::Line(-1, 0);
::Move(0, 1); ::Line(-3, 0);
::Move(-1, -1); ::Line(0, 0);
}
}
else
{
origin = (mRightBottomPointing ? frame.top : frame.bottom - 13);
origin += mTrackOriginTinkering;
if (hasColor)
{
::RGBBackColor(&gAGAColorArray[(disabled ? 4 : 5)]);
Rect tempR = frame;
tempR.top = origin + 3;
tempR.bottom = tempR.top + 5;
tempR.left++;
tempR.right--;
::EraseRect(&tempR);
}
if (disabled)
{
if (hasColor)
::RGBForeColor(&gAGAColorArray[8]);
else
::PenPat(&qd.gray);
}
::MoveTo(frame.left + 2, origin + 4);
::Line((frame.right - frame.left) - 4, 0);
::Move(1, 1); ::Line(0, 2);
::Move(-1, 1); ::Line(-((frame.right - frame.left) - 4), 0);
::Move(-1, -1); ::Line(0, -2);
if (hasColor)
{
::RGBForeColor(&gAGAColorArray[(disabled ? 4 : 5)]);
::Move(-1, -1); ::Line(0, 3);
::MoveTo(frame.right - 1, origin + 4);
::Line(0, 0);
::ForeColor(whiteColor);
::Move(1, 1); ::Line(0, 3);
::Move(-1, 0); ::Line(0, 1);
::Line(-((frame.right - frame.left) - 3), 0);
::Move(-1, -1); ::Line(0, 0);
}
}
}
Boolean LAGASliderBase::TrackHotSpot (Int16 inHotSpot, Point inPoint)
{
// For the initial mouse down, the
// mouse is currently inside the HotSpot
// when it was previously outside
Boolean currInside = true;
Boolean prevInside = false;
HotSpotAction(inHotSpot, currInside, prevInside);
// Track the mouse while it is down
Point currPt = inPoint;
Point referencePt = inPoint;
Boolean showGhost = false;
if (StillDown())
{
Try_
{
InitializeGhost();
while (StillDown())
{
::GetMouse(&currPt);
if (!showGhost)
{
if (((mVerticalSlider ? currPt.v : currPt.h) > ((mVerticalSlider ? referencePt.v : referencePt.h) + kTriggerDistance)) ||
((mVerticalSlider ? currPt.v : currPt.h) < ((mVerticalSlider ? referencePt.v : referencePt.h) - kTriggerDistance)))
showGhost = true;
}
else
DrawGhost(currPt);
}
FinishGhost();
}
Catch_(inErr)
{
}
}
EventRecord macEvent; // Get location from MouseUp event
if (::GetOSEvent(mUpMask, &macEvent))
{
currPt = macEvent.where;
::GlobalToLocal(&currPt);
FinishTrackHotSpot(currPt);
}
// Reset the last know position of the ghost pointer (can't be done in FinishGhost, because
// FinishTrackHotSpot still needs this value
::SetRect(&mLastGhost, 0, 0, 0, 0);
return(true);
}
void LAGASliderBase::HotSpotAction (Int16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside)
{
if (inCurrInside != inPrevInside)
{
FocusDraw();
DrawIndicator(inCurrInside);
}
}
void LAGASliderBase::HotSpotResult (Int16 inHotSpot)
{
// Just draw the pointer with non pushed state, the change of value is performed in FinishTrackHotSpot
HotSpotAction(inHotSpot, false, true);
}
void LAGASliderBase::InitializeGhost ()
{
// Here, we define the GWorld that will contain the ghost pointer
// Subclasses will have to draw the ghost pointer in this GWorld
Rect r, r1;
GetIndicatorRect(r);
r1 = r;
::SetRect(&r, 0, 0, r.right - r.left, r.bottom - r.top);
mGhostPointer = new LGWorld(r);
ThrowIf_(mGhostPointer == nil);
}
void LAGASliderBase::FinishGhost ()
{
if (mGhostPointer != nil)
{
delete mGhostPointer;
mGhostPointer = nil;
}
if (mGhostMask != nil)
{
DisposeRgn(mGhostMask);
mGhostMask = nil;
}
mLastPosition.h = mLastPosition.v = 0;
}